<template>
    <div class="index-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="客户名称" prop="clientId">
                    <el-input class="w-[280px]" v-model="queryParams.clientId" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <div>
                <router-link
                    style="margin-right: 10px"
                    :to="{
                        path: getRoutePath('enterpriseBasicInformation:add')
                    }"
                >
                    <el-button
                        v-perms="['enterpriseBasicInformation:add']"
                        type="primary"
                        @click="handleAdd()"
                    >
                        <template #icon>
                            <icon name="el-icon-Plus" />
                        </template>
                        新增
                    </el-button>
                </router-link>
            </div>
            <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="客户编号" prop="clientId" min-width="180" />
                <el-table-column label=" 注册时间" prop="registerTime" min-width="180" />
                <el-table-column label="注册资金" prop="registerMoney" min-width="180" />
                <el-table-column label="注册类型" prop="registerType" min-width="180" />
                <el-table-column label="单位网址" prop="unitWebsite" min-width="180" />
                <el-table-column
                    label="单位负责人名称"
                    prop="headOfUnitName"
                    min-width="180"
                ></el-table-column>
                <el-table-column label="单位负责人性别" prop="headOfUnitSex" min-width="180" />
                <el-table-column label="单位负责人手机" prop="headOfUnitPhone" min-width="180" />
                <el-table-column label="单位负责人电话" prop="headOfUnitNumber" min-width="180" />
                <el-table-column label="单位负责人职务" prop="headOfUnitPost" min-width="180" />
                <el-table-column label="单位负责人邮箱" prop="headOfUnitEmail" min-width="180" />
                <el-table-column label="公司主营产品（服务）" prop="mainProducts" min-width="180" />
                <el-table-column
                    label="主营业务所属技术领域"
                    prop="mainBusinessBelongs"
                    min-width="230"
                />
                <el-table-column label="上游产品" prop="upstreamProducts" min-width="180" />
                <el-table-column label="下游产品" prop="downstreamProducts" min-width="180" />
                <el-table-column
                    label="规上企业入库备案"
                    prop="isStorageForRecord"
                    min-width="180"
                />
                <el-table-column
                    label="研发费用加计扣除"
                    prop="isAdditionalDeduction"
                    min-width="180"
                />
                <el-table-column label="园区或基地注册" prop="isParkRegistration" min-width="180" />
                <el-table-column
                    label="园区或基地名称"
                    prop="parkRegistrationName"
                    min-width="180"
                />
                <el-table-column
                    label="是否建有博士科研工作站"
                    prop="isDoctoralResearchStation"
                    min-width="230"
                />
                <el-table-column label="进站博士(生)" prop="doctorPitStop" min-width="180" />
                <el-table-column
                    label="设备固定资产总额（万元）"
                    prop="totalEquipment"
                    min-width="230"
                />
                <el-table-column
                    label="未来1-3年计划新增生产设备投入总额（万元）"
                    prop="futureTotal"
                    min-width="350"
                />
                <el-table-column
                    label="信息化软件投入金额"
                    prop="amountOfInvestment"
                    min-width="180"
                />
                <el-table-column
                    label="信息化软件投入具体"
                    prop="ofInvestmentBeSpecific"
                    min-width="180"
                />
                <el-table-column
                    label="信息化软件投入其他"
                    prop="ofInvestmentOthers"
                    min-width="180"
                />
                <el-table-column
                    label="业务系统是否向云端迁移"
                    prop="isCloudMigration"
                    min-width="230"
                />
                <el-table-column
                    label="是否拥有制造业与互联网试点示范项目"
                    prop="isDemonstrationProject"
                    min-width="300"
                />
                <el-table-column label="土地建设" prop="constructionOfLand" min-width="180" />
                <el-table-column label="上市情况" prop="listingStatus" min-width="180" />
                <el-table-column label="上市进程" prop="goToMarketProcess" min-width="180" />
                <el-table-column label="拟上市地" prop="placeOfListing" min-width="180" />
                <el-table-column label="融资需求额" prop="amountOfFinancingNeed" min-width="180" />
                <el-table-column
                    label="计划融资方式"
                    prop="plannedFinancingMethod"
                    min-width="180"
                />
                <el-table-column label="销售收入" prop="revenueFromSales" min-width="180" />
                <el-table-column label="总资产" prop="totalAssets" min-width="180" />
                <el-table-column label="净资产" prop="netWorth" min-width="180" />
                <el-table-column label="净利润" prop="netProfit" min-width="180" />
                <el-table-column label="净利润率" prop="netProfitMargin" min-width="180" />
                <el-table-column label="总负债" prop="totalLiabilities" min-width="180" />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['enterpriseBasicInformation:matchingItem']"
                            type="primary"
                            link
                            @click="handleEdit(row)"
                            ><router-link
                                :to="{
                                    path: getRoutePath('enterpriseBasicInformation:matchingItem'),
                                    query: {
                                        id: row.id
                                    }
                                }"
                            >
                                匹配项目
                            </router-link>
                        </el-button>
                        <el-button
                            v-perms="['enterpriseBasicInformation:edit']"
                            type="primary"
                            link
                        >
                            <router-link
                                :to="{
                                    path: getRoutePath('enterpriseBasicInformation:edit'),
                                    query: {
                                        id: row.id
                                    }
                                }"
                            >
                                编辑
                            </router-link>
                        </el-button>
                        <el-button
                            v-perms="['detail:del']"
                            type="danger"
                            link
                            @click="handleDelete(row.id)"
                        >
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>
<script lang="ts" setup name="detail">
import { detailDelete, detailLists } from '@/api/clientdetail'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
import { getRoutePath } from '@/router'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
    clientId: '',
    registerTime: '',
    registerMoney: '',
    registerType: '',
    unitWebsite: '',
    headOfUnitName: '',
    headOfUnitSex: '',
    headOfUnitPhone: '',
    headOfUnitNumber: '',
    headOfUnitPost: '',
    headOfUnitEmail: '',
    mainProducts: '',
    mainBusinessBelongs: '',
    upstreamProducts: '',
    downstreamProducts: '',
    isStorageForRecord: '',
    isAdditionalDeduction: '',
    isParkRegistration: '',
    parkRegistrationName: '',
    isDoctoralResearchStation: '',
    doctorPitStop: '',
    totalEquipment: '',
    futureTotal: '',
    amountOfInvestment: '',
    ofInvestmentBeSpecific: '',
    ofInvestmentOthers: '',
    isCloudMigration: '',
    isDemonstrationProject: '',
    constructionOfLand: '',
    listingStatus: '',
    goToMarketProcess: '',
    placeOfListing: '',
    amountOfFinancingNeed: '',
    plannedFinancingMethod: '',
    revenueFromSales: '',
    totalAssets: '',
    netWorth: '',
    netProfit: '',
    netProfitMargin: '',
    totalLiabilities: '',
    researchAndDevelopmentExpenses: '',
    proportion: '',
    amountOfTaxPaid: '',
    assetLiabilityRatio: '',
    bankLoan: '',
    volumeOfExports: '',
    totalNumber: '',
    socialSecurity: '',
    personalIncomeTax: '',
    personnelNumber: '',
    phd: '',
    master: '',
    phdLg: '',
    masterLg: '',
    undergraduate: '',
    specialistDepartment: '',
    undergraduateLg: '',
    specialistDepartmentLg: '',
    seniorProfessionaTitle: '',
    intermediateProfessionalTitle: '',
    juniorProfessionalTitle: '',
    returnFromStudyAbroad: '',
    productName: '',
    annualOutputValue: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: detailLists,
    params: queryParams
})

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await detailDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
